package com.example.administrator.day8_15customviewdemo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2016/8/15.
 */
public class MyButton extends View{

    private Paint mPaint;
    private Matrix matrix;
    private Bitmap backBitmap;
    private Bitmap slideBitmap;
    private Rect rectOff;

    public MyButton(Context context) {
        super(context);
        init();
    }

    public MyButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    //初始化一个画笔
    private void init(){
        //创建画笔对象
        mPaint = new Paint();
        //设置文字的大小
//        mPaint.setTextSize();
        //设置画笔的颜色
//        mPaint.setColor();
        //设置画笔的类型
//        mPaint.setTypeface();
        //消除折线  使其不出现锯齿状
        mPaint.setAntiAlias(true);
        matrix = new Matrix();
    }

    //设置图片的资源
    public void setImageBitmap(int backgroundResId,int slideResId){
        //获取背景图片
        backBitmap = BitmapFactory.decodeResource(getResources(), backgroundResId);
        //获取滑动的图片
        slideBitmap = BitmapFactory.decodeResource(getResources(), slideResId);
        //定义一个关闭状态的矩形
        rectOff = new Rect(0, 0, slideBitmap.getWidth(), slideBitmap.getHeight());
        //定义一个开启状态的矩形
        new Rect(backBitmap.getWidth()-slideBitmap.getWidth(),0,backBitmap.getWidth(),slideBitmap.getHeight());
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
